<?php

namespace App\Http\Controllers;

use Illuminate\Support\Facades\DB;

class MailList extends Base
{

    public function logic()
    {
        $uid    = $this->uid;
        $row    = DB::table('t_mail_info')->where('uid', $uid)->orderBy('create_time','desc')->where('status', 1)->get()->map(function ($value) {
            return (array)$value;
        });
        $ac_arr = array();
        foreach ($row as $key => $a) {
            $arr['id']          = (int)$a['id'];
            $arr['to_uid']      = (int)$a['uid'];
            $arr['head']        = $a['head'];
            $arr["content"]     = $a['content_type'] > 0 ? json_decode($a['content'],true) : $a['content'];
            $arr["is_read"]      = (int)$a["is_read"];
            $arr["is_get"]      = (int)$a["is_get"];
            $arr["create_time"] = $a["create_time"];
            $arr["type"]        = $a["type"];
            //附件邮件额外返回数据
            if ($a['type'] == 2) {
                $rule_arr = explode('|', $a['rule']);
                foreach ($rule_arr as $value) {
                    $value_arr          = explode(':', $value);
                    $item_conf = DB::table('t_item_conf')->where('id',$value_arr[0])->first(['icon_id','name']);
                    $arr['icon_list'][] = [
                        'icon_id' => $item_conf->icon_id,
                        'name' => $item_conf->name,
                        'num' => $value_arr[1]
                    ];
                }
            }
            $arr['content_type'] =  $a['content_type'];
            $ac_arr[] = $arr;
            unset($arr);
        }
        return $this->returnData(array("mail_list" => $ac_arr));
    }

}
